package com.ruifu.bom.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fhzncloud.cloud.common.security.util.SecurityUtils;
import com.ruifu.bom.dto.MaterielImportDTO;
import com.ruifu.bom.mapper.MeteringUnitsMapper;
import com.ruifu.bom.service.MeteringUnitsService;
import com.ruifu.common.eneity.BaseEntityPlus;
import com.ruifu.common.po.MeteringUnits;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Wrapper;
import java.util.List;

/**
 * 计量单位业务逻辑层实现类
 *
 * @author nyr
 * @create 2019/12/19
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MeteringUnitsServiceImpl extends ServiceImpl<MeteringUnitsMapper, MeteringUnits> implements MeteringUnitsService {
    @Autowired(required = false)
    private MeteringUnitsMapper meteringUnitsMapper;

    @Override
    public R unitsName(List<MaterielImportDTO> materielImportDTOList) {
        for (MaterielImportDTO materielImportDTO : materielImportDTOList) {
            List<MeteringUnits> meteringUnitsList = meteringUnitsMapper.selectList(Wrappers.<MeteringUnits>lambdaQuery()
                    .eq(MeteringUnits::getMuChineseName, materielImportDTO.getMuChineseName())
                    .eq(BaseEntityPlus::getSetSid, SecurityUtils.getUser().getTenantId()));
            if (meteringUnitsList.isEmpty()) {
                return R.failed("不存在此单位");
            }
        }
        return null;
    }
}